package com.baidu.foodrecipe.ui.fragment.joke

import android.os.Bundle
import android.view.MotionEvent
import android.view.View
import androidx.fragment.app.viewModels
import com.baidu.foodrecipe.base.BaseFragment

import com.baidu.foodrecipe.databinding.FragmentJokeBinding

class JokeFragment : BaseFragment<FragmentJokeBinding>() {
    private val jokeViewModel: JokeViewModel by viewModels()

    override fun initUI(savedInstanceState: Bundle?) {
        super.initUI(savedInstanceState)
        jokeViewModel.getJoke()

        jokeViewModel.text.observe(viewLifecycleOwner) {
            mBinding.tvJoke.text = it
        }

        mBinding.root.setOnClickListener {
            jokeViewModel.getJoke()
        }


        mBinding.scrollView.setOnTouchListener { v, event ->
            if (event.action == MotionEvent.ACTION_UP) {
                // 当ScrollView被触摸时，也触发CardView点击
                mBinding.root.performClick();
            }
            false; // 不消费事件，让ScrollView正常滚动
        }

    }
}